﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace RandomElvenName
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        String[] pref;
        String[] suf;

        private void bnOpenFile_Click(object sender, EventArgs e)
        {            
            OpenFileDialog f = new OpenFileDialog();
            f.ShowDialog();            
            System.IO.StreamReader st = new System.IO.StreamReader(f.FileName);

            String str = st.ReadToEnd();
            String[] strn = new String[2];

            char[] separator = { '\r', '\n' };
            char[] sep = { '$' };

            strn = str.Split(sep, StringSplitOptions.RemoveEmptyEntries);
            pref = strn[0].Split(separator, StringSplitOptions.RemoveEmptyEntries);
            suf = strn[1].Split(separator, StringSplitOptions.RemoveEmptyEntries);            
        }

        private void bnGenerate_Click(object sender, EventArgs e)
        {
            Random rand = new Random();
            int p, s1, s2;
            double flg=rand.NextDouble();
            if (flg > 0.5)
            {
                p = rand.Next(pref.Length - 1);
                s1 = rand.Next(suf.Length - 1);
                s2 = rand.Next(suf.Length - 1);

                tbName.Text += pref[p] + suf[s1] + suf[s2]+"\r\n";                
            }
            else
            {
                p = rand.Next(pref.Length - 1);
                s1 = rand.Next(suf.Length - 1);
                
                tbName.Text += pref[p] + suf[s1] + "\r\n";
            }
        }                         
    }
}
